package top.layne.cloud.tsf.consumer.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import top.layne.cloud.tsf.api.entity.BmsCoupon;
import top.layne.cloud.tsf.consumer.service.CouponService;

import java.util.List;

/**
 * @author : layne
 * @Date: 2020/7/27
 * @Time: 11:18
 * Description:
 */
@RestController
public class CouponController {
    private static final Logger LOGGER = LoggerFactory.getLogger(CouponController.class);


    @Autowired
    private CouponService couponService;
    @Autowired
    private RestTemplate restTemplate;


    @GetMapping("/coupon-feign/getCouponList")
    public List<BmsCoupon> getCouponList(Integer pageNum, Integer pageSize) {
        LOGGER.info(">>>>>getCouponList :{},{}", pageNum, pageSize);
        return couponService.getCouponList(pageNum, pageSize);
    }

    @GetMapping("/coupon-rest/getCouponList")
    public List<BmsCoupon> getRestCouponList(Integer pageNum, Integer pageSize) {
        LOGGER.info(">>>>>getRestCouponList :{},{}", pageNum, pageSize);
        return restTemplate.getForObject("http://layne-cloud-tsf-database/coupon/getCouponList?pageNum=" + pageNum + "&pageSize=" + pageSize, List.class);
    }


}
